<?php
/**
 * CheckDaySchedule function
 *
 * Return schedule for specified day.
 *
 * @author Will Zhao <kexinzhao666@gmail.com>
 */
require_once("SCconn_.php");
require_once 'UTerrorcode.php';
require_once 'UTcheckAuth.php';
/**
 * @param $userName string
 * @param $userPassHash string
 * @param $Date string
 * @return array|null
 */
function checkDaySchedule($userName, $userPassHash, $Date)
{
    $err=new ErrorCode();
	$us=$userName;
	//$us='Chen';
	if(checkAuthentication($userName,$userPassHash))
	{
		$conn=mysql_open();
		mysql_select_db("paradigmshift_dev", $conn);
		$iDate=date('y/m/d',strtotime(trim($Date)));
		//$iDate='2013-01-25';
		$result=mysql_query("select paradigmshift_dev.account.accName,roles.roleName,
paradigmshift_dev.roledate.startTime,
paradigmshift_dev.roledate.endTime,
paradigmshift_dev.roledate.shiftStatus,
paradigmshift_dev.dates.datestamp from  
paradigmshift_dev.employees left join (dates,roledate,account,roles) 
on paradigmshift_dev.roledate.empID=employees.empID and
paradigmshift_dev.account.empID=paradigmshift_dev.employees.empID and
paradigmshift_dev.dates.dateID=paradigmshift_dev.roledate.dateID 
and roles.roleID=roledate.roleID
where dates.datestamp = '".$iDate."'",$conn);
		/*echo "<table id='users' class='ui-widget ui-widget-content'>
		 <thead>
		<tr class='ui-widget-header '>
		<th>roleID</th>
		<th>empID</th>
		<th>dateID</th>
		<th>StartDate</th>
		<th>EndDate</th>
		<th>shiftStatus</th>
		<th>date</th>
		</tr>
		</thead>";*/
		$count=mysql_num_rows($result);
		if ($count<=0)
	    {
		     return null;
		     $error =$err->failRead;
		}
		while($row=mysql_fetch_array($result))
		{
			$array[] = array(
			'accName'=>$row['accName'],
			'roleName'=>$row['roleName'],
			'startTime'=>$row['startTime'],
			'endTime'=>$row['endTime'],
			'shiftStatus'=>$row['shiftStatus'],
			'date'=>$row['datestamp']);
		}
		mysql_close($conn);
		//return $result;
		return $array;
		$error=$err->successRead;

	}
	else
	{
		//echo 'unknow user';
		$error =$err->failRead;
	}
}

?>